package com.spzx.test1.t13Caguan2;

import lombok.SneakyThrows;

import java.util.concurrent.*;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CookRoom {
    Lock lock = new ReentrantLock();
    Condition cookLock = lock.newCondition();
    Condition cutLock = lock.newCondition();
    Condition giveLock = lock.newCondition();

    String foodStatus = "cut";

    // 定义一个共享的阻塞队列
    BlockingQueue<String> taskQueue1 = new ArrayBlockingQueue<>(5);
    BlockingQueue<String> taskQueue2 = new ArrayBlockingQueue<>(5);
    BlockingQueue<String> taskQueue3 = new ArrayBlockingQueue<>(5);

    // 线程池

    @SneakyThrows
    public String cut() {


            taskQueue1.put("切菜完毕，下面交给炒菜");
            return "开始切菜";



    }

    @SneakyThrows
    public String cook() {
        String take = taskQueue1.take();
        taskQueue2.put("炒菜完毕，下面交给端菜");
        return take;
    }

    @SneakyThrows
    public String give() {
        String take = taskQueue2.take();

        return take;
    }


    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(3);
        CookRoom cookRoom = new CookRoom();
        executor.submit(() -> {
            for (int i = 0; i < 10; i++) {

                System.out.println(cookRoom.cut()+i);
            }
        });


        executor.submit(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(cookRoom.cook()+i);
            }
        });

        executor.submit(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(cookRoom.give()+i);
                System.out.println("给顾客吃"+i);
            }
        });
    }
}